<template>
	<div class="apply-container">
		<!-- 监理申请列表 -->
		<Table border :columns="columns1" :data="applyList"></Table>
		<!-- 分页 -->
		<br />
		<div style="text-align: center;">
			<Page :total="total" show-elevator @on-change="changeUser" />
		</div>
	</div>
</template>

<script>
	import path from '@/api/path.js';
	let url = path.url;
	import axios from '@/libs/api.request';
	export default {
		data(){
			return {
				columns1: [{
						title: '活动编号',
						key: 'id',
						width: 100,
						align: 'center'
					},
					{
						title: '小区名称',
						key: 'address',
						align: 'center'
					},
					{
						title: '参与时间',
						key: 'createTime',
						align: 'center'
					},
					{
						title: '状态',
						key: 'status',
						width: 100,
						align: 'center'
					},
					{
						title: '操作',
						key: 'action',
						width: 150,
						align: 'center',
						render: (h, params) => {
							return h('div', [
								h('Button', {
									props: {
										type: 'primary',
										size: 'small'
									},
									style: {
										marginRight: '10px'
									},
									on: {
										click: (e) => {
											this.delApply(params.row.id);
										}
									}
								}, '取消订单')
							]);
						}
					}
				],
				applyList: [],
				page: 1,
				total: 0
			}
		},
		props: ['id'],
		methods: {
			// 获取当前用户的监理申请信息
			getSupervisorApplyList(){
				axios.request({
					url: `${url}SupervisionApply/getSupervisionApplyList`,
					method: 'post',
					data: {
						id: this.id,
						page: this.page
					}
				}).then(res=>{
					if ( res.data.status == 1 ) {
						this.applyList = res.data.content.data;
						this.total = res.data.content.total;
						this.applyList.forEach(item=>{
							if ( item.status == 1 ) {
								item.status = '未联系'
							} else {
								item.status = '已联系'
							}
						})
					} else {
						throw '获取用户信息中的监理申请数据失败'
					}
				})
			},
			// 分页跳转
			changeUser(idx) {
				this.page = idx;
				this.getSupervisorApplyList();
			},
			// 监理申请取消订单
			delApply(idx) {
				axios.request({
					url: `${url}SupervisionApply/delSupervisionApply`,
					method: 'post',
					data: {
						id : idx
					}
				}).then(res=>{
					console.log(res);
					if ( res.data.status == 1 ) {
						this.getSupervisorApplyList();
					} else {
						throw '取消监理申请订单失败! '
					}
				})
			}
		},
		created(){
			this.getSupervisorApplyList();
		}
	}
</script>

<style>

</style>
